package com.example.demo.thread;

import java.util.concurrent.TimeUnit;

/**
 * @author Code Farmer
 * @date 2020/6/12 19:06
 */
public class ThreadLocalDemo {

    static ThreadLocal<Integer> t1 = new ThreadLocal<>();

    public static void main(String[] args) {
        new Thread(() -> { //t1

            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            System.out.println("线程1获取数据：" + t1.get());

        }).start();

        new Thread(() -> { //t2
            t1.set(new Integer(1));
        }).start();
    }

}
